package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.front.config.wechat.WxMpUtil;
import com.mdd.front.service.wechat.IWechatService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Map;

/**
 * @author kn4im3
 * @date 2023/3/7 09:38
 */
@RestController
@RequestMapping("/api/wechat")
public class WechatController {
    @Resource
    private IWechatService iWechatService;

    /**
     * 获取jsSdk授权接口
     * @param url 请求连接
     * @return Object
     */
    @GetMapping("/jsConfig")
    public AjaxResult jsConfig(@Validated @NotEmpty() @RequestParam("url") String url) throws Exception {
        iWechatService.jsConfig(url);
        try {
            Map<String, Object> map = iWechatService.jsConfig(url);
            return AjaxResult.success(map);
        }catch (Exception e){
            return AjaxResult.failed(e.getMessage());
        }
    }
}
